package com.classic.duanzhi;

import android.content.Intent;
import android.os.Handler;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.view.View;

import com.classic.adapter.ListAdapter;
import com.classic.base.BaseActivity;
import com.classic.dialog.SelectLabelDialog;

import java.util.ArrayList;
import java.util.List;

/**
 * 段子集中地
 */
public class EpisodeListActivity extends BaseActivity implements SelectLabelDialog.OnItemClickListener {

    @Override
    protected int getLayoutId() {
        return R.layout.ad_activity_episode_list;
    }

    public static final String data_ = "DATA_";

    public static void starThis(FragmentActivity activity, String title) {
        Intent intent = new Intent(activity, EpisodeListActivity.class);
        intent.putExtra(data_, title);
        activity.startActivity(intent);
    }

    public static void starThis(FragmentActivity activity) {
        activity.startActivity(new Intent(activity, EpisodeListActivity.class));
    }

    ViewPager viewpager;

    @Override
    protected void initView() {
        viewpager = findViewById(R.id.viewpager);
        final TabLayout tablayout = findViewById(R.id.tablayout);
        ArrayList<TabModel> tabModels = new ArrayList<>();
        tabModels.add(new TabModel("https://www.biedoul.com", "全部 "));
        tabModels.add(new TabModel("/t/5pCe56yR5ryr55S7", "搞笑漫画 "));
        tabModels.add(new TabModel("/t/6ISR5q6L5a%2B56K%2Bd.html", "脑残对话"));
        tabModels.add(new TabModel("/t/5oG25pCe5Zu%2B54mH.html", "恶搞图片"));
        tabModels.add(new TabModel("/t/5oG25L2c5Ymn.html", "恶作剧"));
        tabModels.add(new TabModel("/t/57OX5LqL.html", "糗事"));
        tabModels.add(new TabModel("/t/54iG56yR572R5paH.html", "爆笑网文"));
        tabModels.add(new TabModel("/t/5bCP56yR6K%2Bd.html", "小笑话"));
        tabModels.add(new TabModel("/t/55%2Bt5L%2Bh56yR6K%2Bd.html", "短信笑话"));
        tabModels.add(new TabModel("/t/56yR6K%2Bd5Zu%2B54mH.html", "笑话图片"));
        tabModels.add(new TabModel("/t/5YaF5ra156yR6K%2Bd.html", "内涵笑话"));
        tabModels.add(new TabModel("/t/5bm96buY5Zu%2B54mH.html", "幽默图片"));
        tabModels.add(new TabModel("/t/54iG56yRZ2lm.html", "爆笑gif"));
        tabModels.add(new TabModel("/t/5pCe56yR55%2Bt5L%2Bh.html", "搞笑短信"));
        tabModels.add(new TabModel("/t/6IGM5Zy656yR6K%2Bd.html", "职场笑话"));
        tabModels.add(new TabModel("/t/6ISR562L5oCl6L2s5byv.html", "脑筋急转弯"));
        tabModels.add(new TabModel("/t/57uP5YW456yR6K%2Bd.html", "经典笑话"));
        tabModels.add(new TabModel("/t/5Ya356yR6K%2Bd.html", "冷笑话"));
        tabModels.add(new TabModel("/t/56We5Zue5aSN.html", "神回复"));
        tabModels.add(new TabModel("/t/5peg6IqC5pON.html", "无节操"));
        tabModels.add(new TabModel("/t/56yR6K%2Bd5aSn5YWo.html", "笑话大全"));
        tabModels.add(new TabModel("/t/5a625bqt6Laj5LqL.html", "家庭趣事"));
        tabModels.add(new TabModel("/t/5qCh5Zut6Laj5LqL.html", "校园趣事"));
        tabModels.add(new TabModel("/t/5pq06LWw5ryr55S7.html", "暴走漫画"));
        tabModels.add(new TabModel("/t/54aK5a2p5a2Q.html", "熊孩子"));
        tabModels.add(new TabModel("/t/5aWz5rGJ5a2Q.html", "女汉子"));
        tabModels.add(new TabModel("/t/5YaF5ra15q615a2Q.html", "内涵段子"));
        tabModels.add(new TabModel("/t/5pCe56yR54Wn54mH.html", "搞笑照片"));
        tabModels.add(new TabModel("/t/576O5aWz5Yqo5oCB5Zu%2B.html", "美女动态图"));
        tabModels.add(new TabModel("/t/54ix5oOF.html", "爱情"));
        tabModels.add(new TabModel("/t/6YeN5Y%2Bj5ZGz.html", "重口味"));
        tabModels.add(new TabModel("/t/5pCe56yR5Zu%2B54mH.html", "搞笑图片"));
        tabModels.add(new TabModel("/t/5pCe56yR5q615a2Q.html", "搞笑段子"));
        tabModels.add(new TabModel("/t/5aSr5aa756yR6K%2Bd.html", "夫妻笑话"));
        tabModels.add(new TabModel("/t/5bm96buY56yR6K%2Bd.html", "幽默笑话"));
        tabModels.add(new TabModel("/t/54iG56yR5Zu%2B54mH.html", "爆笑图片"));
        tabModels.add(new TabModel("/t/5byA5b%2BD5LiA5Yi7.html", "开心一刻"));
        tabModels.add(new TabModel("/t/5bm96buY5oG25pCe.html", "幽默恶搞"));
        tabModels.add(new TabModel("/t/5aW956yR55qE56yR6K%2Bd.html", "好笑的笑话"));
        tabModels.add(new TabModel("/t/54iG56yR5ryr55S7.html", "爆笑漫画"));
        tabModels.add(new TabModel("/t/6IqC5pel56yR6K%2Bd.html", "节日笑话"));
        tabModels.add(new TabModel("/t/56yR6K%2Bd5pWF5LqL.html", "笑话故事"));
        tabModels.add(new TabModel("/t/6Iux6K%2Bt56yR6K%2Bd.html", "英语笑话"));
//        tabModels.add(new TabModel("/tags/", " 更多"));

        ListAdapter listAdapter = new ListAdapter(getSupportFragmentManager(), tabModels);
        viewpager.setAdapter(listAdapter);
        tablayout.setupWithViewPager(viewpager);
        findViewById(R.id.iv_more).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initSelectDialog(tabModels);
            }
        });

        viewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                index = position;
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
//
    }

    private int index = 0;

    private SelectLabelDialog dialog;

    void initSelectDialog(List<TabModel> strings) {
        if (null == dialog) dialog = new SelectLabelDialog(this, strings, this);
        dialog.show(index);
    }

    @Override
    protected void initData() {

    }


    @Override
    public String getActivityTitle() {
        String s = getIntent().getStringExtra(data_);
        return TextUtils.isEmpty(s) ? getResources().getString(R.string.app_name) : s;
    }

    @Override
    public void onClick(int index) {
        viewpager.setCurrentItem(index);
    }
}
